package com.vanzo.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.vanzo.Tpplication;
import com.vanzo.encryption.R;
import com.vanzo.instruction.AT;
import com.vanzo.instruction.Instruction;
import com.vanzo.util.VersionUtil;

/**
 * Created by tisen on 2018/3/6.
 */

public class VersionActivity extends BaseActivity {

    private TextView softwareVersion;
    private TextView talkieVersion;
    private TextView title;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_version);
//        instruction.start();
        softwareVersion = (TextView) findViewById(R.id.software_version);
        talkieVersion = (TextView) findViewById(R.id.talkie_version);
        title = (TextView) findViewById(R.id.tv_title);
        title.setText("关于版本");

        talkieVersion.setText("模块软件版本:" + "null");
        softwareVersion.setText("对讲软件版本:" + VersionUtil.getVersionName(this));
    }

    private Handler uiHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            String version = (String) msg.obj;
            talkieVersion.setText("模块软件版本:" + version);
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        instruction.getVersion(new Instruction.OnResultListener() {
            @Override
            public void onResult(String result) {
                if (result.contains(AT.VERSION)) {
                    int index = result.indexOf(AT.VERSION);
                    String version = result.substring(index + AT.DMO_VERSION.length() - 1);
                    Message message = new Message();
                    message.obj = version;
                    uiHandler.sendMessage(message);
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
